package demo1;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-04-07
 * Time: 19:29
 */
public class SharpenFilter {
    static {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }

    /**
     * Laplace算子增强
     * 用于整体偏暗图像的增强,变亮
     *
     * 存在噪声情况下，使用Laplacian算子检测边缘之前需要先进行低通滤波
     * @param src
     * @return
     */
    public static Mat laplaceEnhance(Mat src) {
        Mat srcClone = src.clone();
        float[] kernel = {0, 0, 0, -1, 5f, -1, 0, 0, 0};
        Mat kernelMat = new Mat(3, 3, CvType.CV_32FC1);
        kernelMat.put(0, 0, kernel);
        Imgproc.filter2D(srcClone, srcClone, CvType.CV_8UC3, kernelMat);
        return srcClone;
    }

    public static void main2(String[] args) {
        Mat src = Imgcodecs.imread("girl.jpg");
        HighGui.imshow("src",src);
        HighGui.waitKey(0);

        Mat mat = laplaceEnhance(src);
        HighGui.imshow("laplace",mat);
        HighGui.waitKey(0);
    }
    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat src = Imgcodecs.imread("src2.png");
        HighGui.imshow("src", src);
        HighGui.waitKey();

        Mat dst = new Mat();
        Mat usm = new Mat();
        Imgproc.GaussianBlur(src, dst, new Size(0, 0), 10, 10);
        Core.addWeighted(src, 1.5, dst, -0.5, 0, usm);
        HighGui.imshow("usm", usm);
        HighGui.waitKey();
    }
}
